﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Interfaces.Web.Twitter
{
    /// <summary>
    /// This class provides the collection of timeline data from twitter accounts.
    /// </summary>
    [Serializable]
    public class TimelineDataCollector : AbstractDataCollector
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TimelineDataCollector"/> class.
        /// </summary>
        /// <param name="connectionInformation">The connection information of the twitter account.</param>
        public TimelineDataCollector(Connection connectionInformation)
            : base(connectionInformation)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TimelineDataCollector"/> class.
        /// </summary>
        /// <param name="connectionInformation">The connection information of the twitter account.</param>
        /// <param name="userlist">The user list of the accounts from which the information should be collected.</param>
        public TimelineDataCollector(Connection connectionInformation, List<string> userlist)
            : base(connectionInformation, userlist)
        {
        }

        /// <summary>
        /// Collects the timeline data from the specified twitter accounts.
        /// </summary>
        /// <returns>The collected timeline data.</returns>
        public List<List<TimelineItem>> CollectTimelineData()
        {
            List<List<TimelineItem>> result = new List<List<TimelineItem>>();
            Twitter twitter = new Twitter(this.ConnectionInformation);

            for (int i = 0; i < this.Userlist.Count; i++)
            {
                List<TimelineItem> tempuri = twitter.GetUserTimeline(this.Userlist[i]);

                if (tempuri != null)
                {
                    if (tempuri.Count != 0)
                    {
                        result.Add(tempuri);
                    }
                }
            }

            return result;
        }
    }
}